package com.ds.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ds.common.annotation.Log;
import com.ds.common.core.controller.BaseController;
import com.ds.common.core.domain.AjaxResult;
import com.ds.common.enums.BusinessType;
import com.ds.applet.domain.MiniSlideshow;
import com.ds.applet.service.IMiniSlideshowService;
import com.ds.common.utils.poi.ExcelUtil;
import com.ds.common.core.page.TableDataInfo;

/**
 * 小程序首页轮播图Controller
 *
 * @author liucan
 * @date 2024-03-23
 */
@RestController
@RequestMapping("/slideshow/slideshow")
public class MiniSlideshowController extends BaseController {
    @Resource
    private IMiniSlideshowService miniSlideshowService;

    @Resource
    private MiniLeagueController miniLeagueController;

    /**
     * 查询小程序首页轮播图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniSlideshow miniSlideshow, HttpServletRequest request) {
        startPage();
        miniSlideshow.setToApplet(miniLeagueController.toApplet(request));
        List<MiniSlideshow> list = miniSlideshowService.selectMiniSlideshowList(miniSlideshow);
        return getDataTable(list);
    }

    /**
     * 新增小程序首页轮播图
     */
    @Log(title = "小程序首页轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniSlideshow miniSlideshow, HttpServletRequest request) {
        miniSlideshow.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniSlideshowService.insertMiniSlideshow(miniSlideshow));
    }

    /**
     * 修改小程序首页轮播图
     */
    @Log(title = "小程序首页轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniSlideshow miniSlideshow, HttpServletRequest request) {
        miniSlideshow.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniSlideshowService.updateMiniSlideshow(miniSlideshow));
    }

    /**
     * 删除小程序首页轮播图
     */
    @Log(title = "小程序首页轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniSlideshowService.deleteMiniSlideshowByIds(ids));
    }


    /**
     * 获取小程序首页轮播图详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniSlideshowService.selectMiniSlideshowById(id));
    }

    /**
     * 导出小程序首页轮播图列表
     */
    @Log(title = "小程序首页轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniSlideshow miniSlideshow) {
        List<MiniSlideshow> list = miniSlideshowService.selectMiniSlideshowList(miniSlideshow);
        ExcelUtil<MiniSlideshow> util = new ExcelUtil<MiniSlideshow>(MiniSlideshow.class);
        util.exportExcel(response, list, "小程序首页轮播图数据");
    }
}
